<?php
class Mcatab extends CI_Model
{
    protected $_table = "tbl_catab";
    function __construct() {
        parent::__construct();
        $this->load->database();
    }
    function getOptions()
    {
        $result = $this->db->get($this->_table)->result();
        $options = array();
        foreach ($result as $type)
        {
            $options[$type->id] = $type->name;
        }
        return $options;
    }
    function get_limit($limit=3) {
        return $this->db
            ->order_by("id","DESC")
            ->where('status',1)
            ->limit($limit)
            ->get($this->_table)->result_array();
    }
    public function listall($off,$start){
        $this->db->order_by("id","DESC");
        $this->db->limit($off,$start);
        return $this->db->get($this->_table)->result_array();
    }
    function get_name($id) {
        return $this->db
            ->select('name')
            ->where('status',1)
            ->where('id',$id)
            ->get($this->_table)->row_array();
    }
    function get_all() {
        $this->db->where('status',1);
        $this->db->order_by("id","asc");
        return $this->db->get($this->_table)->result_array();
    }
    function check_uri($uri){
        $this->db->where("url",$uri);
        $query=$this->db->get($this->_table);
        if($query->num_rows() == 0){
            return FALSE;
        }else{
            return $query->row_array();
        }
    }
    public function count_all(){
        return $this->db->count_all($this->_table);
    }
    public function add($data){
        $this->db->insert($this->_table,$data);
    }
    public function del($id){
        $this->db->where("id",$id);
        $this->db->delete($this->_table);
    }
    public function detail($id) {
        return $this->db
            ->where('id', $id)
            ->get($this->_table)
            ->result_array();
    }
    function get_id() {
        return $this->db
            ->select('id,name')
            ->get($this->_table)
            ->result_array();
    }
    function get_idk($id,$limit=4) {
        return $this->db
            ->where('id !=', $id)
            ->limit($limit)
            ->get($this->_table)
            ->result_array();
    }
    function getOne($id){
        $this->db->where("id",$id);
        $this->db->where('status',1);
        $query = $this->db->get($this->_table);
        return $query->row_array();
    }
    public function get_data($id){
        $this->db->where("id",$id);
        $query = $this->db->get($this->_table);
        return $query->row_array();
    }
    public function update($data,$id){
        $this->db->where("id",$id);
        $this->db->update($this->_table,$data);
    }
    public function update_status($data,$id){
        $this->db->where("id",$id);
        $this->db->update($this->_table,$data);
    }
}
?>